#include "Config.h"
#include "PlayerObject.h"
#include "Object.h"
#include <SDL_image.h>

#define GFX_PATH "gfx/player.png"
#define GFX_TOGGLE_PATH "gfx/splatter.png"

SDL_Surface *PlayerObject::sTexture = 0;
SDL_Surface *PlayerObject::sTextureToggle = 0;

int
PlayerObject::PreloadGraphic()
{
  sTexture = IMG_Load(GFX_PATH);
  if (!sTexture)
    return E_ERROR;
  
  sTextureToggle = IMG_Load(GFX_TOGGLE_PATH);
  if (!sTextureToggle)
    return E_ERROR;

  return E_OK;
}


// #pragma mark -


PlayerObject::PlayerObject(Engine *parent, unsigned int x, unsigned int y)
  : Object(x, y, parent)
{
  if (!sTexture) {
    int err;
    err = PreloadGraphic(); 
    if (err < E_OK)
      throw int(err);
  }

  fGraphic = sTexture;
}

PlayerObject::~PlayerObject()
{
}

bool
PlayerObject::ToggleState()
{
  if (fState) {
    fGraphic = sTextureToggle;
    fState = false;
  }
  else {
    fGraphic = sTexture;
    fState = true;
  }
  return fState;
}
